<template>
  <div class="login">
    <div class="_wz_login_main">
      <div class="_wz_login_main_cent">
        <div>
          <img src="../../assets/121.png" @error="public.imgDispose" />
          <span>交通运输企业安全生产标准化自主双控平台1111</span>
        </div>
        <Form ref="formInline" :model="formInline" :rules="ruleInline">
          <FormItem prop="username">
            <i-input type="text" v-model="formInline.username" placeholder="用户名" clearable/>
          </FormItem>
          <FormItem prop="password">
            <i-input type="password" v-model="formInline.password" placeholder="密码" @keyup.enter.native="handleSubmit('formInline')" clearable/>
          </FormItem>
          <FormItem>
            <Button class="_wz_black_button" type="primary" @click="handleSubmit('formInline')" long>登录</Button>
          </FormItem>
        </Form>
      </div>
    </div>
    <div class="_wz_foot">
      <span>备案序号：冀ICP备18004049号-2</span>
      <span>CopyRight © 河北信达交通科技有限公司</span>
      <span>技术支持：河北信达交通科技有限公司</span>
    </div>
  </div>
</template>


<script>
  import global from "../../api/common";

  export default {
    data() {
      return {
        studentCode: null,//学员二维码
        overtime: true,//超时
        timedRequestLogin: null,//定时请求数据
        studentsScanCode: false,
        imgSrc: "",
        formInline: {
//        username: 'admin',
//        password: 'xdbj2018'
        },
        ruleInline: {
          username: [
            {required: true, message: '请填写用户名', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '请填写密码', trigger: 'blur'}
          ]
        },
        loginKey: {},

        visible: false,
      }
    },
    mounted() {//mounted 挂载结束状态
      if (!!!localStorage.getItem('systemStyle')) {
        localStorage.setItem('systemStyle', JSON.stringify({
          "subjectColor": "_wz_1d1e23",
          "systemStyle": "top",
          "multiTabbed": false
        }))
      }
    },
    methods: {
      handleSubmit(name) {
        var that = this;
        that.$refs[name].validate((valid) => {
          if (valid) {
            that.formInline.grant_type = "password";
            that.formInline.scope = "read write";
            that.formInline.client_id = "xd-client";
            that.formInline.client_secret = "xd-secret";
            that.formInline.platformCode = "SAFETY";
            that.formInline.platformClient= "PC";
            that.$Spin.show();
            var data = that.qs.stringify(that.formInline);

            that.axios.post(that.apiUrl.oauthToken, data, {headers: {'Content-Type': "application/x-www-form-urlencoded"}})
            .then(res => {


              sessionStorage.setItem("loginData", JSON.stringify(res.data));
              that.loadNav.loadNav();
              that.$Spin.hide();
              that.$Message.success({
                content: "登录成功",
                onClose: function () {
                  that.$router.push({
                    path: that.public.getHomePage()
                  })
                }
              });
            }).catch(err => {
              that.$Spin.hide();
              console.log("失败", err)
            })
          } else {
            that.$Message.error('请输入账号密码进行登录');
          }
        })
      },
    }
  }
</script>

<style lang="less">


  .login {
    background: #373d41 !important;
    width: 100%;
    height: 100%;

    ._wz_login_main {
      height: 100%;
      background-image: url("../../assets/back.png");
      background-size: cover;
      background-position: center;
      position: relative;
      display: flex;
      text-align: center;
      align-content: center;

      ._wz_login_main_cent {
        align-content: center;
        width: 350px;
        margin: auto;
        color: #fff;
        text-align: center;
        font-size: 26px;
        line-height: 60px;
        letter-spacing: 1px;

        img {
          width: 150px;
          display: block;
          margin: auto;
        }
      }


      .ivu-form {
        margin: 20px 0 0;

        .ivu-form-item-content {
          margin: 10px 0;
        }

        .ivu-input {
          color: #fff;
          border: 0;
          border-radius: 0;
          border-bottom: 1px solid #fff;
          background: none;
        }
      }

      ._wz_black_button {
        background-color: #23222c;
        border-color: #23222c;
        height: 35px;
      }

      ._wz_black_button:hover {
        color: #fff;
        background-color: #43424c;
        border-color: #43424c;
      }
    }

  }

  /*.ivu-spin-fix{*/
  /*background-color:rgba(0,0,0,0.6);*/
  /*}*/
  .login_vertical-center-modal {
    display: flex;
    align-items: center;
    justify-content: center;

    .ivu-modal {
      top: 0;
    }
  }
</style>
<style lang="less" scoped>
  ._wz_foot {
    position: absolute;
    bottom: 0px;
    left: 0px;
    right: 0px;
    background: #313131;
    height: 40px;
    line-height: 40px;
    text-align: center;
    color: #fff;

    span {
      margin: 0 15px;
      letter-spacing: 2px;
    }
  }


  ._wz_qrcode {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 6px;
    display: inline-block;
    margin: auto;
    position: relative;

    img {
      display: block;
    }
  }


</style>
